package wechat.app.corp.domain;

import java.util.ArrayList;
import java.util.Date;
import org.apache.log4j.Logger;
import org.eclipse.xtext.xbase.lib.CollectionLiterals;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import wechat.app.WXServiceAppFactoryDemo;
import wechat.base.snd.WCServiceApp;
import wechat.base.snd.WCTemplateContent;
import wechat.base.snd.WCTemplateNews;
import wechat.base.snd.util.TimeFormatter;

@SuppressWarnings("all")
public class ScheduledTaskNotifyWeiXin {
  private static Logger logger = new Function0<Logger>() {
    public Logger apply() {
      Logger _logger = Logger.getLogger("ScheduledTaskNotify");
      return _logger;
    }
  }.apply();
  
  private static String SERVICE_APP_TEMPLATE_DISPATH_MSG_URL = "http://operation.linemore.com/customertaskdetails";
  
  private static String SERVICE_APP_TEMPLATE_DISPATH_MSG_URL_NO_AUTH = "http://operation.linemore.com/customertaskdetails_ext";
  
  private static String TEMPLATE_DISPATH_MSG_ID = "v_CkyFvYjwXJq525Au4Lv71rslPW5pwcye3vPtBNlTU";
  
  public static WCServiceApp sendTemplateMsg_ServApp_WithAuth(final Iterable<String> wechatids, final String eventId, final Date arrivalTime, final String engineerName, final String taskDesc) {
    WCServiceApp _serviceApp = WXServiceAppFactoryDemo.getServiceApp();
    final Procedure1<WCServiceApp> _function = new Procedure1<WCServiceApp>() {
        public void apply(final WCServiceApp it) {
          WCTemplateNews _createTemplateNews = it.createTemplateNews();
          final Procedure1<WCTemplateNews> _function = new Procedure1<WCTemplateNews>() {
              public void apply(final WCTemplateNews it) {
                it.withTempId(ScheduledTaskNotifyWeiXin.TEMPLATE_DISPATH_MSG_ID);
                WCTemplateContent _wCTemplateContent = new WCTemplateContent();
                final Procedure1<WCTemplateContent> _function = new Procedure1<WCTemplateContent>() {
                    public void apply(final WCTemplateContent it) {
                      it.withFirstItem("\u62A5\u4FEE\u72B6\u6001\u5982\u4E0B\uFF1A");
                      it.withKeyword1Item(taskDesc);
                      it.withKeyword2Item(engineerName);
                      String _timeFormat = TimeFormatter.timeFormat(arrivalTime);
                      String _plus = ("\u4E0A\u95E8\u65F6\u95F4\uFF1A" + _timeFormat);
                      it.withRemarkItem(_plus);
                    }
                  };
                WCTemplateContent _doubleArrow = ObjectExtensions.<WCTemplateContent>operator_doubleArrow(_wCTemplateContent, _function);
                it.withData(_doubleArrow);
                it.withAuthUrl(ScheduledTaskNotifyWeiXin.SERVICE_APP_TEMPLATE_DISPATH_MSG_URL, eventId);
                it.send2Users(wechatids);
              }
            };
          ObjectExtensions.<WCTemplateNews>operator_doubleArrow(_createTemplateNews, _function);
        }
      };
    WCServiceApp _doubleArrow = ObjectExtensions.<WCServiceApp>operator_doubleArrow(_serviceApp, _function);
    return _doubleArrow;
  }
  
  public static void sendTemplateMsg_ServApp_NoAuth(final Iterable<String> wechatids, final String eventId, final Date arrivalTime, final String engineerName, final String taskDesc) {
    final WCServiceApp app = WXServiceAppFactoryDemo.getServiceApp();
    final Procedure1<String> _function = new Procedure1<String>() {
        public void apply(final String user) {
          WCTemplateNews _createTemplateNews = app.createTemplateNews();
          final Procedure1<WCTemplateNews> _function = new Procedure1<WCTemplateNews>() {
              public void apply(final WCTemplateNews it) {
                it.withTempId(ScheduledTaskNotifyWeiXin.TEMPLATE_DISPATH_MSG_ID);
                WCTemplateContent _wCTemplateContent = new WCTemplateContent();
                final Procedure1<WCTemplateContent> _function = new Procedure1<WCTemplateContent>() {
                    public void apply(final WCTemplateContent it) {
                      it.withFirstItem("\u62A5\u4FEE\u72B6\u6001\u5982\u4E0B\uFF1A");
                      it.withKeyword1Item(taskDesc);
                      it.withKeyword2Item(engineerName);
                      String _timeFormat = TimeFormatter.timeFormat(arrivalTime);
                      String _plus = ("\u4E0A\u95E8\u65F6\u95F4\uFF1A" + _timeFormat);
                      it.withRemarkItem(_plus);
                    }
                  };
                WCTemplateContent _doubleArrow = ObjectExtensions.<WCTemplateContent>operator_doubleArrow(_wCTemplateContent, _function);
                it.withData(_doubleArrow);
                String _plus = (ScheduledTaskNotifyWeiXin.SERVICE_APP_TEMPLATE_DISPATH_MSG_URL_NO_AUTH + "?evtid=");
                String _plus_1 = (_plus + eventId);
                String _plus_2 = (_plus_1 + "&wechatid=");
                String _plus_3 = (_plus_2 + user);
                it.withUrl(_plus_3);
                ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList(user);
                it.send2Users(_newArrayList);
              }
            };
          ObjectExtensions.<WCTemplateNews>operator_doubleArrow(_createTemplateNews, _function);
        }
      };
    IterableExtensions.<String>forEach(wechatids, _function);
  }
  
  public static void sendTemplateMsg_ServApp_NoAuth_ext(final String openid, final String eventId, final Date reportTime, final String engineerName, final String taskDesc) {
    String _plus = ("Find a user " + openid);
    InputOutput.<String>println(_plus);
    ArrayList<String> _newArrayList = CollectionLiterals.<String>newArrayList(openid);
    wechat.app.domain.ScheduledTaskNotifyWeiXin.sendTemplateMsg_ServApp_NoAuth(_newArrayList, eventId, reportTime, engineerName, taskDesc);
  }
}
